//package com.yuan.spring.messagequeue.redisqueue.newimpl;
//
//import org.springframework.aop.support.AopUtils;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.config.BeanPostProcessor;
//import org.springframework.beans.factory.support.BeanDefinitionBuilder;
//import org.springframework.beans.factory.support.DefaultListableBeanFactory;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.core.MethodIntrospector;
//import org.springframework.core.annotation.AnnotationUtils;
//import org.springframework.data.redis.listener.PatternTopic;
//
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//
///**
// * redisListen 注解 processor
// *
// * @author yuaneg 2018/12/3
// */
//public class RedisListenProcessor implements BeanPostProcessor, ApplicationContextAware {
//
//    private ApplicationContext applicationContext;
//
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        this.applicationContext = applicationContext;
//    }
//
//    @Override
//    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//        Class<?> targetClass = AopUtils.getTargetClass(bean);
//        Map<Method, RedisListen> annotatedMethods = MethodIntrospector.selectMethods(targetClass, this::inspect);
//        annotatedMethods.forEach((method, redisListen) -> {
//            List<PatternTopic> patternTopicList = new ArrayList<>();
//            Arrays.asList(redisListen.value()).forEach(chat -> patternTopicList.add(new PatternTopic(chat)));
//            DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
//            BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageListenerAdapterWrapper.class);
//            beanDefinitionBuilder.addConstructorArgValue(bean);
//            beanDefinitionBuilder.addConstructorArgValue(method.getName());
//            beanDefinitionBuilder.addConstructorArgValue(patternTopicList);
//            defaultListableBeanFactory.registerBeanDefinition("#" + beanName + method.getName(), beanDefinitionBuilder.getBeanDefinition());
//        });
//        return bean;
//    }
//
//    private RedisListen inspect(Method method) {
//        return AnnotationUtils.findAnnotation(method, RedisListen.class);
//    }
//
//}
